<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue.min.js"></script>
    <script src="../../js/iview.min.js"></script>
    <link rel="stylesheet" href="../../css/iview.css">
</head>
<body>
<div id="app" style="padding: 50px">
    <p>总数:{{total}}</p>
    <my-component @increase="handleGetTotal"
                  @reduce="handleGetTotal"></my-component>

</div>
<script>
    Vue.component('my-component', {
        template: "\
        <div>\
        <button @click='handleIncrease'>+1</button>\
        <button @click='handleReduce'>-1</button>\
        ",
        data: function () {
            return {
                count: 0
            }
        },
        methods: {
            handleIncrease: function () {
                this.count++;
                this.$emit('increase', this.count);
            },
            handleReduce: function () {
                this.count--;
                this.$emit('reduce', this.count);
            }
        }

    });
    var app = new Vue({
        el: "#app",
        data: {
            total: 0
        },
        methods: {
            handleGetTotal: function (total) {
                this.total = total;
            }
        }
    })
</script>
</body>
</html>